-
-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw an error if structural simplification is applied twice (take 2) #3035
Conversation
0c63790
to
d1dbfcc
Compare
It doesn't make sense to have completion not mean that the system is complete. If you want to make that be a V10 then make it a v10, but we shouldn't just have it be a random name that doesn't match what it's doing |
@@ -28,8 +28,6 @@ jobs: | |||
group: | |||
- InterfaceI | |||
- InterfaceII | |||
- SymbolicIndexingInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just reverted together. I can add them back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot to not delete the tests...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -251,6 +251,7 @@ end | |||
0 ~ z - cos(x), | |||
0 ~ x * y] | |||
@named ns = NonlinearSystem(eqs, [x, y, z], []) | |||
ns = complete(ns) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
@@ -158,8 +158,8 @@ function level2() | |||
eqs = [D(x) ~ p1 * x - p23[1] * x * y | |||
D(y) ~ -p23[2] * y + p4 * x * y] | |||
|
|||
sys = structural_simplify(ODESystem( | |||
eqs, t, tspan = (0, 3.0), name = :sys, parameter_dependencies = [y0 => 2p4])) | |||
sys = structural_simplify(complete(ODESystem( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the whole point of complete
. People can write sys = complete(sys)
so that namespacing just works out for plot(sol, idxs=sys.v)
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But they don't use the indexing, and they immediately call structural simplify here which would set complete itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am just saying calling complete before is valid use and should be tested.
@@ -32,62 +32,57 @@ end | |||
@safetestset "Dynamic Quantities Test" include("dq_units.jl") | |||
@safetestset "Unitful Quantities Test" include("units.jl") | |||
@safetestset "Mass Matrix Test" include("mass_matrix.jl") | |||
@safetestset "SteadyStateSystem Test" include("steadystatesystems.jl") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are the tests moved back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change just got reverted with your PR.
@@ -12,6 +12,3 @@ end | |||
@safetestset "Bareiss" begin | |||
include("bareiss.jl") | |||
end | |||
@safetestset "Errors" begin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this test deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You added these changes in the #3027 PR and just reverted together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you revert this change though? I don't see why you wouldn't want a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your PR is actually breaking though. And |
Let's actually read the docs:
|
Well it says two things, it says the model is complete and it says that the indexing is changed. If you want, we can fix this with a v10, but having the iscomplete not actually mean the model is complete is not a good idea. |
|
If it's complete then ... . It's not saying a model is complete if and only if it indexes like that. The if only defines one extra property. It marks that the model was completed, and it also signifies that it will change its indexing behavior. And it wouldn't make sense for it to be the iff either: if I was to say "I have completed building this model" and you had never used MTK, would your first though be "so therefore it drops the top level scope"? No one would guess complete means that, so if this primitive is supposed to mean that, it should really be deprecated to a different name. But at the same time, we need a marker for completeness since other optimizations in the near future will require knowing that property, so we still need something for "this model has been completed" |
Mark a system as completed. If a system is complete, the system will no longer namespace its
subsystems or variables, i.e. isequal(complete(sys).v.i, v.i). This is the documented definition of |
The definition of sys = complete(sys)
s = structural_simplify(sys) is a common and valid use of |
Let's just change the words a bit and see if the logic makes sense. Doc string: issquare. Marks that the object is a square. If the object is a square then it is red. Is it breaking to think that issquare is true means that the object is a square? Or can we only assume that something that issquare is red? If that's the case, why is it not called isred? |
If you're going to revert then, there's no reason to revert the other test changes. Can we just do this right instead? |
Is the definition of
sys = complete(sys)
s = structural_simplify(sys) is a common and valid pattern, and 3027 breaks that. |
You are making I defined |
Okay, then what about yanking, fixing the definitions and picking good descriptive names, and doing a v10? |
I think |
So you think if we went to the modelica conference and asked people what it meant for a model to be complete is, you think that is the definition they would give? You don't think they would say that it meant they were done changing the model? I get that we read the docstring differently. And I see how you could have meant it to mean something different. But let's take a step back here, it's getting emotional. I really don't think that is what most people would expect complete to mean, we will need a sense of completion for other optimizations we add in the near future to be valid, and we can make things better. How about picking more clear words, splitting these meanings, and doing a v10? It also doesn't make sense that top level indexing changes are one way. Why not allow for flipping that on and off? Tying it to a form of finalization and making it a one way operation is the problem some others are having with ergonomics. If we split this idea from completion, then we can make it swappable and fix other ergonomics issues Ben was having. That seems like a good reason to take the moment to do the real fix and v10 |
Yeah, It still doesn't mean |
Yes, it doesn't necessarily mean that a model is simplified, but if it means "a modeler will no longer change the model", shouldn't you error in structural simplify since they are now changing the model? |
Structural simplify is not stateful. It just returns another object, so they are not changing the model. |
A modelica person typically does not invoke structural simplification themselves, they press play and the tool performs translation and simulation, so I'm pretty sure they consider the model complete when they hand it off to the tool to do it's thing. FWIW, I completely agree with Yingbo in this matter |
If complete is about symbolic indexing and the numerical function building codes don't use the symbolic indexing, why error if calling ODEProblem on a model that isn't complete? If that's what it means then it doesn't make sense to mix it with that. |
It should error because then the Programmatically, it means |
Okay, I think I am seeing a different definition from you now:
Is that correct? So okay, I am fine with this definition of "cannot change the model" to mean "cannot mutate the model", and thus structural simplification is fine. If this is the case:
|
I maintain the definition that Normally, |
Let's be more precise. With that definition of complete, we should validate that there are no unbound inputs (with a keyword arg to turn off the check) and check units at that point too? |
We could if we want but it has nothing to do with this PR being merged as a fix for MTK v9. |
Since this PR is a non-breaking strict improvement compare to the broken state right now, I will merge and tag a new release. |
This shouldn't've merged without fixing the tests though... |
#3035 accidentally reverted fixes to the test setup and checks that the error is thrown
SciML#3035 accidentally reverted fixes to the test setup and checks that the error is thrown
Reverts #3027 Fixes #3012